/**
 * Project Name:JavaBaseReview
 * Package Name:com.xuwei.ext.design_pattern.observer
 * author:David
 * Date:2016年5月11日下午5:27:31
 * Copyright (c) 2016, xw123box@126.com All Rights Reserved.
 *
 */
package com.xuwei.ext.design_pattern.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author David
 * @since 2016年5月11日 下午5:27:31
 * @version 
 * @since JDK 1.6
 */
public class Subject {
	private List<Observer> observers = new ArrayList<Observer>();
	private int state;
	
	public int getState(){
		return state;
	}
	
	public void setState(int state){
		this.state = state;
		notifyAllObservers();
	}

	public void attach(Observer observer){
		observers.add(observer);
	}
	
	public void notifyAllObservers() {
		for(Observer observer:observers){
			observer.update();
		}
	}

}
